//
//  UIButton+Extension.swift
//  个人微博
//
//  Created by guo3920591 on 16/4/16.
//  Copyright © 2016年 guo3920591. All rights reserved.
//

import UIKit

extension UIButton {
    /// 创建 UIButton
    ///
    /// - parameter gxl_title:   gxl_title 文字
    /// - parameter titleColor:  titleColor 默认darkGrayColor
    /// - parameter titleFont:   titleFont  默认16
    /// - parameter imgName:     imgName  默认nil
    /// - parameter backImgName: backImgName 默认nil
    ///
    /// - returns: UIButton
    convenience init(gxl_title: String?,
        titleColor: UIColor = UIColor.darkGrayColor(),
        titleFont: CGFloat = 16,
        imgName: String? = nil,
        backImgName: String? = nil) {
            
            self.init()
            
            self.setTitle(gxl_title, forState: .Normal)
            self.setTitleColor(titleColor, forState: .Normal)
            self.titleLabel?.font = UIFont.systemFontOfSize(titleFont)
            
            if let imgName = imgName{
                self.setImage(UIImage(named: imgName), forState: .Normal)
                self.setImage(UIImage(named: imgName + "_highlighted"), forState: .Highlighted)
            }
            
            if let backImgName = backImgName{
                self.setBackgroundImage(UIImage(named: backImgName), forState: .Normal)
                self.setBackgroundImage(UIImage(named: backImgName + "_highlighted"), forState: .Highlighted)
                
            }
            
            sizeToFit()
            
    }
    
    
    
    
    
}
